package com.ftwj.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ftwj.config.resp.ResultMessage;
import com.ftwj.entity.SchoolPlaceInfo;
import com.ftwj.entity.SysMenu;
import com.ftwj.service.SchoolPlaceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;

@RestController
@Slf4j
@RequestMapping("/school-place")
public class SchoolPlaceController {
    @Autowired
    private SchoolPlaceService schoolPlaceService;

    @GetMapping("/Select-ByName")
    public ResultMessage selectSchoolPlaceInfoByName(@RequestParam("name") String name,
                                                     @RequestParam("page") int page,
                                                     @RequestParam("size") int size) {
        Page<Object> paging = new Page<>(page, size);
        IPage<Map<String, Object>> result = schoolPlaceService.selectSchoolPlaceInfoByName(paging, name);
        return ResultMessage.success(result);
    }

    @GetMapping("/Select-All")
    public ResultMessage selectSchoolPlaceInfoAll(@RequestParam("page") int page,
                                                  @RequestParam("size") int size) {
        Page<Object> paging = new Page<>(page, size);
        IPage<Map<String, Object>> result = schoolPlaceService.selectSchoolPlaceInfoAll(paging);
        return ResultMessage.success(result);
    }

    @PutMapping("/Update")
    public ResultMessage updateSchoolPlaceInfo(@RequestBody SchoolPlaceInfo schoolPlaceInfo) {
        int rows = schoolPlaceService.updateSchoolPlaceInfo(schoolPlaceInfo);
        return rows > 0 ?ResultMessage.success() : ResultMessage.error();
    }

    @PutMapping("/Update-OpenState")
    public ResultMessage updateSchoolPlaceOpenState(@RequestBody SchoolPlaceInfo schoolPlaceInfo) {
        int rows = schoolPlaceService.updateSchoolPlaceOpenState(schoolPlaceInfo);
        return rows > 0 ?ResultMessage.success() : ResultMessage.error();
    }

    @DeleteMapping("/Delete/{id}")
    public ResultMessage deleteSchoolPlaceInfoById(@PathVariable("id") String id){
        int flag = schoolPlaceService.deleteSchoolPlaceInfoById(id);
        return flag> 0 ? ResultMessage.success() : ResultMessage.error();
    }

    @PostMapping("/Insert")
    public ResultMessage insertSchoolPlaceInfo(@RequestBody SchoolPlaceInfo schoolPlaceInfo) {
        int rows = schoolPlaceService.insertSchoolPlaceInfo(schoolPlaceInfo);
        return rows> 0 ? ResultMessage.success() : ResultMessage.error();
    }

}
